﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Learn_lock
{
    class Program
    {
        private static object locker = new object();
        static void Main(string[] args)
        {
            for (int i = 0; i < 5; i++)
            {
                new Thread(PrintNumbers).Start();
            }
        }

        static void PrintNumbers()
        {
            lock (locker)
            {
                for (int i = 1; i < 5; i++)
                {
                    Console.WriteLine(i + " ");
                    Thread.Sleep(100);
                }
                Console.WriteLine();
            }
        }
    }
}
